package ${packageName}.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.spark.common.annotation.Dict;
import com.spark.common.annotation.query.Query;
import com.spark.common.annotation.valid.Password;
import com.spark.common.constants.QueryConstants;
import com.spark.common.constants.RegexConstants;
<#if model?? && model == "tree">
import com.spark.common.core.entity.BaseTreeEntity;
<#else >
import com.spark.common.core.entity.BaseEntity;
</#if>
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.*;

/**
 * ${functionName}
 *
 * @author ${author}
 * @date ${datetime}
 */
@Data
@TableName("${tableName}")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
<#if model?? && model == "tree">
public class ${className} extends BaseTreeEntity<${className}> {
<#else >
public class ${className} extends BaseEntity {
</#if>

<#list fields as field>
    /**
     * ${field.fieldAnnotation}
    <#if (field.fieldRemark??) && (field.fieldRemark?trim?has_content)>
     *  : ${field.fieldRemark}
    </#if>
     */
    <#-- 查询条件 -->
    <#if field.openQuery?? && field.openQuery>
        <#if field.queryType?? && field.queryType == "EQ">
    @Query
        <#else >
    @Query(QueryConstants.QUERY_${field.queryType})
        </#if>
    </#if>
    <#-- 是否为空校验 -->
    <#if field.validation.canNotNull?? && field.validation.canNotNull>
        <#if field.fieldType?contains("String")>
    @NotBlank(message = "${field.fieldAnnotation}不能为空")
        <#else >
    @NotNull(message = "${field.fieldAnnotation}不能为空")
        </#if>
    </#if>
    <#-- 数据长度校验 -->
    <#if (field.validation.validationMin?? && field.validation.validationMin != 0) && (field.validation.validationMax?? && field.validation.validationMax != 0)>
    @Size(min = ${field.validation.validationMin}, max = ${field.validation.validationMax}, message = "${field.fieldAnnotation}长度应在${field.validation.validationMin}到${field.validation.validationMax}之间")
    <#elseif field.validation.validationMin?? && field.validation.validationMin == 0 && field.validation.validationMax?? && field.validation.validationMax != 0>
    @Max(value = ${field.validation.validationMax}, message = "${field.validation.fieldAnnotation}最多${field.validation.validationMax}个字符")
    <#elseif field.validation.validationMin?? && field.validation.validationMin != 0 && (field.validation.validationMax?? && field.validation.validationMax == 0)>
    @Min(value = ${field.validation.validationMin}, message = "${field.validation.fieldAnnotation}最少${field.validation.validationMin}个字符")
    </#if>
    <#-- 正则校验 -->
    <#if field.validation?? && field.validation.openPattern?? && field.validation.openPattern>
        <#if field.validation.patternType?? && field.validation.patternType == 0>
            <#if field.validation.regexp?? && field.validation.regexp == "EMAIL_REGEX">
    @Email(message = "请输入有效的电子邮件地址")
            <#elseif field.validation.regexp?? && field.validation.regexp == "PASSWORD_REGEX">
    @Password
            <#else >
    @Pattern(regexp = RegexConstants.${field.validation.regexp}, message = "${field.validation.regexpMsg}")
            </#if>
        <#else>
    @Pattern(regexp = "${field.validation.regexp}", message = "${field.validation.regexpMsg}")
        </#if>
    </#if>
    <#-- 字典注解 -->
    <#if field.dict?? && field.dict.openDict?? && field.dict.openDict>
        <#if field.dict.dictType?? && field.dict.dictType == 0>
    @Dict(dictCode = "${field.dict.dictCode}")
        <#else >
    @Dict(dictTable = "${field.dict.dictTable}", dictCode = "${field.dict.dictCode}", dictText = "${field.dict.dictText}")
        </#if>
    </#if>
    private ${field.fieldType} ${field.fieldName};

</#list>
}
